package com.example.demo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {

    private Button btnStart;
    private ProgressBar progressBar;
    private ProgressBar progressBar2;
    private ProgressBar progressBar3;
    private ProgressBar progressBar4;
    private TextView txv;

    private SeekBar seekBar;
    private RatingBar ratingBar;
    private TextView txv2;
    private TextView txv3;

    private int progress=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        btnStart = findViewById(R.id.btn_start);
        txv = findViewById(R.id.txv);
        progressBar = findViewById(R.id.progressBar);
        progressBar2 = findViewById(R.id.progressBar2);
        progressBar3 = findViewById(R.id.progressBar3);
        progressBar4 = findViewById(R.id.progressBar4);

        seekBar = findViewById(R.id.seekBar);
        ratingBar = findViewById(R.id.ratingBar);
        txv2 = findViewById(R.id.txv2);
        txv3 = findViewById(R.id.txv3);

        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnStart.setText("增加进度");
                if (progress == 0) {
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar2.setVisibility(View.VISIBLE);
                    progressBar3.setVisibility(View.VISIBLE);
                    progressBar4.setVisibility(View.VISIBLE);
                } else if (progress <= 100) {
                    progressBar.setProgress(progress);
                    progressBar2.setProgress(progress);
                    progressBar3.setProgress(progress);
                    progressBar4.setProgress(progress);
                }else{
//                    progressBar.setVisibility(View.GONE);
//                    progressBar2.setVisibility(View.GONE);
//                    progressBar3.setVisibility(View.GONE);
//                    progressBar4.setVisibility(View.GONE);
//                    btnStart.setVisibility(View.GONE);
                    btnStart.setClickable(false);
                    return ;
                }
                txv.setText("当前进度为：" + progress + "%");
                progress +=10;
            }
        });

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                //进度条发生改变时触发
                txv2.setText("当前进度为：" + progress + "%");
                Log.i("SeekBar", "当前进度为：" + progress + "%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                //按住时触发
                Log.i("SeekBar", "按住SeekBar");
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                //松开始触发
                Log.i("SeekBar", "松开SeekBar");
            }
        });

        ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                txv3.setText("当前获得"+rating+"星！");
                Log.i("RatingBar", rating + "星");
            }

        });
    }
}